<template>
  <div class="app-container">
    <div class="div-sch">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="姓名" prop="staffName">
          <el-input
            v-model="queryParams.staffName"
            placeholder="请输入姓名"
            clearable
            style="width: 240px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="设备" prop="deviceId">
          <el-input
            v-model="queryParams.deviceId"
            placeholder="请输入设备"
            clearable
            style="width: 240px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="通行时间">
        <el-date-picker
          v-model="queryParams.passTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
         <el-button
            type="warning"
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            style="position:absolute;right:30px;"
            v-hasPermi="['monitor:operlog:export']"
          >导出</el-button>
      </el-form>
    </div>
    <div class="div-t">
      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table ref="tables"  border v-loading="loading"   :data="list" @selection-change="handleSelectionChange" :default-sort="defaultSort" @sort-change="handleSortChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="姓名"  align="center" prop="staffName" />
        <el-table-column label="登记照"  align="center" prop="img" width="100">
          <template slot-scope="scope">
            <el-image 
              style="width: 50px; height: 50px"
              :src="setImg(scope.row.img)" 
              :preview-src-list="[setImg(scope.row.img)]">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column label="抓拍照" align="center" prop="faceImage" width="100">
          <template slot-scope="scope">
            <el-image 
              style="width: 50px; height: 50px"
              :src="setImg(scope.row.faceImage)" 
              :preview-src-list="[setImg(scope.row.faceImage)]">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column label="场景照" align="center" prop="sceneImage" width="100">
          <template slot-scope="scope">
            <el-image 
              style="width: 50px; height: 50px"
              :src="setImg(scope.row.sceneImage)" 
              :preview-src-list="[setImg(scope.row.sceneImage)]">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column label="标签" align="center" prop="isPass">
          <template slot-scope="scope">
            <el-tag :type="scope.row.isPass?'success':'danger'">{{scope.row.isPass?'访客':'陌生人'}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="通行设备" align="center" minWidth="120" prop="deviceName"></el-table-column>
        <el-table-column label="通行时间" align="center" minWidth="120" prop="accessTime"/>
        <el-table-column label="相识度" align="center" prop="similarity">
          <template slot-scope="scope">
            {{scope.row.similarity | similarityUnit}}
          </template>
        </el-table-column>
        <el-table-column label="体温" align="center" prop="temp"/>
        <el-table-column label="通行结果" align="center" prop="isPass">
          <template slot-scope="scope">
            <el-tag :type="scope.row.isPass?'success':'danger'">{{scope.row.isPass?'刷脸通过':'刷脸未通过'}}</el-tag>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

    </div>
  </div>
</template>
<script>
import { userRecordApi } from "@/api/business/record";
import badImg from '@/assets/images/bad_img.jpg';
export default {
  name: "recordList",
  components: {},
  dicts: ['sys_oper_type', 'sys_common_status'],
  data() {
    return {
      tableHeight:0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 是否显示弹出层
      saveModal:{
        // 弹出层标题
        title: "",
        open: false,
        isUpdate: false,
        updateData: undefined,
      },
      // 默认排序
      defaultSort: {prop: 'operTime', order: 'descending'},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isAsc: 'desc',
        orderByColumn:'accessTime',
        staffName: undefined,
        deviceId: undefined,
        passTime: undefined
      },
      // 表单校验
      rules: {
        tagName: [
          { required: true, message: "标签名称不能为空", trigger: "blur" }
        ]
      }
    };
  },
  filters:{
    similarityUnit(val){
      if(val){
        return (Number(val)).toFixed(2)+"%"
      }
      return ''
    }
  },
  created() {
    this.getList();
    this.getTableHeight();
  },
  methods: {
    getTableHeight(){
      this.tableHeight = window.innerHeight - 300;
    },
    /** 查询 */
    getList() {
      this.loading = true;
      userRecordApi.getUserRecords(this.queryParams).then( res => {
          this.list = res.data.records;
          this.total = res.data.total;
          this.loading = false;
        }
      ).catch(err=>{
        this.loading = false;
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.passTime = [];
      this.resetForm("queryForm");
      this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order)
      this.handleQuery();
    },
    /** 多选框选中数据 */
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.tagIds = selection.map(item => item.tagId)
      this.multiple = !selection.length
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/access/export/batch', {
        ...this.queryParams
      }, `通行记录_${new Date().getTime()}.xlsx`)
    },
    // 表单重置
    reset() {
      this.form = {};
    },
    // 取消按钮
    cancel() {
      this.saveModal.open = false;
      this.reset();
    },
    /** 提交按钮 */
    submitForm: function() {
     
    },
    setImg(img){
      return img? "data:image/jpg;base64," + img : badImg;
    },
  }
};
</script>
<style  >
.div-t {
  background: white;
  padding: 10px 10px 20px 10px;
  border-radius: 5px;
  /* border: 1px solid rgb(211, 208, 208); */
}
.div-sch {
  background: white;
  padding: 10px 10px 0px 10px;
  border-radius: 5px;
  margin-bottom: 10px;
}
img{
  cursor: pointer;
}
/* .switchStyle .el-switch__label {
    position: absolute;
    display: none;
    color: #fff;
  }
 .el-switch__core{
    background-color: rgba(166, 166, 166, 1) ;
  }
  .switchStyle .el-switch__label--left {
    z-index: 9;
    left: 8px;
  }
  .switchStyle .el-switch__label--right {
    z-index: 9;
    left: -15px;
  }
  .switchStyle .el-switch__label.is-active {
    display: block;
  }
  .switchStyle.el-switch .el-switch__core,
  .el-switch .el-switch__label {
    width: 60px !important;
  } */
</style>